// index.js
import request from '../../utils/request'
Page({
    data:{
      bannerList:[],//轮播图数据
      recommendList:[], //推荐歌单
      topList:[], //排行榜数据
      mvList:[] , //歌手推荐
      // navItems:[
      // {name:'每日推荐',iconfont:'iconfont icon-tuijian1'},
      // {name:'歌单',iconfont:'iconfont icon-gedan'},
      // {name:'排行榜',iconfont:'iconfont icon-paihangbang'},
      // {name:'电台',iconfont:'iconfont icon-diantaizhibo'},
      // {name:'直播',iconfont:'iconfont icon-shipinzhibo'}
      // ]
    },

    //跳转到每日推荐歌曲页面
    toRecommendSong(){
      wx.navigateTo({
        url: '/songPackage/pages/recommendSong/recommendSong',
      })
    },
    
    // 生命周期函数--监听页面加载
    onLoad:async function(options){
      
      let bannerListData=await request('/banner',{type:2})
      
      console.log(this.data.bannerList);

      // 获取推荐歌单数据
      let recommendListData=await request('/personalized',{limit:10})
      this.setData({
        bannerList:bannerListData.banners,
        recommendList:recommendListData.result
      })

      // 获取排行榜数据
      // 需求分析:
      // 1.需要根据idx的值获取对应的数据
      // 2.idx的取值范围是0-20,我们需要0-4,（发送五次请求）
      // let index=0
      // let resultArr=[]
      // while(index<5){
      //   let topListData=await request('/top/list',{idx:index++})
      //   // console.log('topListData:',topListData);
      //   let topListItem={name:topListData.playlist.name,tracks:topListData.playlist.tracks.slice(0,3)}
      //   resultArr.push(topListItem)
      //   // 更新topList的状态值
      //   this.setData({
      //     topList:resultArr
      //   })
      // }

      //获取mv排行
      let mvListData = await request('/top/mv',{limit:10});
      this.setData({
        mvList: mvListData.data
        
      })
    }
})
